#include "showinfowindow.h"

#include <QCursor>
#include <QGridLayout>
#include "debug.h"

showinfoWindow::showinfoWindow(QWidget* parent):QDialog(parent)
{
    //设置固定大小
    setFixedSize(QSize(450, 225));
    setWindowIcon(QIcon(":/resource/images/logo.png"));
    setWindowTitle("个人信息");
    //设置自动销毁
    setAttribute(Qt::WA_DeleteOnClose);
    move(QCursor::pos());  //移动到点击位置

    //网格布局
    QGridLayout* layout = new QGridLayout();
    layout->setHorizontalSpacing(10);
    layout->setVerticalSpacing(4);
    layout->setContentsMargins(20, 20, 20, 0);
    layout->setAlignment(Qt::AlignTop);
    setLayout(layout);

    int width = 50;
    int height = 30;

    avatarBtn = new QPushButton();
    avatarBtn->setFixedSize(75, 75);
    avatarBtn->setIconSize(QSize(75, 75));


    QString tagSS = "QLabel {font-size:14px; font-weight: 800;}";
    QString btnSS = "QPushButton {border: none; background-color: transparent;}";
    btnSS += "QPushButton:pressed {background-color: rgb(205, 205, 205)}";
    QString editSS = "QLineEdit {padding-left: 2px; border: none; border-radius: 5px;}";

    //id
    idTag = new QLabel();
    idTag->setText("序号");
    idTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    idTag->setFixedSize(width, height);
    idTag->setStyleSheet(tagSS);

    idLabel = new QLabel();
    idLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    idLabel->setFixedHeight(height);

    //name
    nameTag = new QLabel();
    nameTag->setText("昵称");
    nameTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    nameTag->setFixedSize(width, height);
    nameTag->setStyleSheet(tagSS);

    nameLabel = new QLabel();
    nameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    nameLabel->setFixedHeight(height);

    nameBtn = new QPushButton();
    nameBtn->setFixedSize(75, 25);
    nameBtn->setIconSize(QSize(20, 20));
    nameBtn->setIcon(QIcon(":/resource/images/modify.png"));
    nameBtn->setStyleSheet(btnSS);

    nameModifyEdit = new QLineEdit();
    nameModifyEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    nameModifyEdit->setFixedHeight(height);
    nameModifyEdit->setStyleSheet(editSS);
    nameModifyEdit->hide();

    nameSubmitBtn = new QPushButton();
    nameSubmitBtn->setFixedSize(75, 25);
    nameSubmitBtn->setIconSize(QSize(20, 20));
    nameSubmitBtn->setIcon(QIcon(":/resource/images/submit.png"));
    nameSubmitBtn->setStyleSheet(btnSS);
    nameSubmitBtn->hide();


    //desc
    descTag = new QLabel();
    descTag->setText("签名");
    descTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    descTag->setFixedSize(width, height);
    descTag->setStyleSheet(tagSS);

    descLabel = new QLabel();
    descLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    descLabel->setFixedHeight(height);

    descBtn = new QPushButton();
    descBtn->setFixedSize(75, 25);
    descBtn->setIconSize(QSize(20, 20));
    descBtn->setIcon(QIcon(":/resource/images/modify.png"));
    descBtn->setStyleSheet(btnSS);

    descModifyEdit = new QLineEdit();
    descModifyEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    descModifyEdit->setFixedHeight(height);
    descModifyEdit->setStyleSheet(editSS);
    descModifyEdit->hide();

    descSubmitBtn = new QPushButton();
    descSubmitBtn->setFixedSize(75, 25);
    descSubmitBtn->setIconSize(QSize(20, 20));
    descSubmitBtn->setIcon(QIcon(":/resource/images/submit.png"));
    descSubmitBtn->setStyleSheet(btnSS);
    descSubmitBtn->hide();

    //phone
    phoneTag = new QLabel();
    phoneTag->setText("电话");
    phoneTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    phoneTag->setFixedSize(width, height);
    phoneTag->setStyleSheet(tagSS);

    phoneLabel = new QLabel();
    phoneLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    phoneLabel->setFixedHeight(height);

    phoneBtn = new QPushButton();
    phoneBtn->setFixedSize(75, 25);
    phoneBtn->setIconSize(QSize(20, 20));
    phoneBtn->setIcon(QIcon(":/resource/images/modify.png"));
    phoneBtn->setStyleSheet(btnSS);

    phoneModifyEdit = new QLineEdit();
    phoneModifyEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    phoneModifyEdit->setFixedHeight(height);
    phoneModifyEdit->setStyleSheet(editSS);
    phoneModifyEdit->hide();

    phoneSubmitBtn = new QPushButton();
    phoneSubmitBtn->setFixedSize(75, 25);
    phoneSubmitBtn->setIconSize(QSize(20, 20));
    phoneSubmitBtn->setIcon(QIcon(":/resource/images/submit.png"));
    phoneSubmitBtn->setStyleSheet(btnSS);
    phoneSubmitBtn->hide();

    //验证码
    verifyCodeTag = new QLabel();
    verifyCodeTag->setText("验证码");
    verifyCodeTag->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    verifyCodeTag->setFixedSize(width, height);
    verifyCodeTag->setStyleSheet(tagSS);
    verifyCodeTag->hide();

    verifyCodeEdit = new QLineEdit();
    verifyCodeEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    verifyCodeEdit->setFixedHeight(height);
    verifyCodeEdit->setStyleSheet(editSS);
    verifyCodeEdit->hide();

    getVerifyCodeBtn = new QPushButton();
    getVerifyCodeBtn->setText("验证码");
    getVerifyCodeBtn->setFixedSize(70, height);
    getVerifyCodeBtn->setStyleSheet("QpushButton {border: none; background-color: transaprent; border-radius: 7px}");
    getVerifyCodeBtn->hide();


    //添加到布局管理中
    layout->addWidget(avatarBtn, 0, 0, 3, 1);

    //id
    layout->addWidget(idTag, 0, 1);
    layout->addWidget(idLabel, 0, 2);

    //name
    layout->addWidget(nameTag, 1, 1);
    layout->addWidget(nameLabel, 1, 2);
    layout->addWidget(nameBtn, 1, 3);

    //签名
    layout->addWidget(descTag, 2, 1);
    layout->addWidget(descLabel, 2, 2);
    layout->addWidget(descBtn, 2, 3);

    //phone
    layout->addWidget(phoneTag, 3, 1);
    layout->addWidget(phoneLabel, 3, 2);
    layout->addWidget(phoneBtn, 3, 3);

    //verifyCode
    layout->addWidget(verifyCodeTag, 4, 1);
    layout->addWidget(verifyCodeEdit, 4, 2);
    layout->addWidget(getVerifyCodeBtn, 4, 3);


    //添加槽函数
    connect(nameBtn, &QPushButton::clicked, this, [=](){
        nameLabel->hide();
        nameBtn->hide();
        layout->removeWidget(nameLabel);
        layout->removeWidget(nameBtn);
        nameModifyEdit->show();
        nameSubmitBtn->show();
        nameModifyEdit->setText(nameLabel->text());
        layout->addWidget(nameModifyEdit, 1, 2);
        layout->addWidget(nameSubmitBtn, 1, 3);
    });

    connect(descBtn, &QPushButton::clicked, this, [=](){
        descLabel->hide();
        descBtn->hide();
        layout->removeWidget(descLabel);
        layout->removeWidget(descBtn);
        descModifyEdit->show();
        descSubmitBtn->show();
        descModifyEdit->setText(descLabel->text());
        layout->addWidget(descModifyEdit, 2, 2);
        layout->addWidget(descSubmitBtn, 2, 3);
    });

    connect(phoneBtn, &QPushButton::clicked, this, [=](){
        phoneLabel->hide();
        phoneBtn->hide();
        layout->removeWidget(phoneLabel);
        layout->removeWidget(phoneBtn);
        phoneModifyEdit->show();
        phoneSubmitBtn->show();
        verifyCodeEdit->show();
        verifyCodeTag->show();
        getVerifyCodeBtn->show();
        phoneModifyEdit->setText(phoneLabel->text());
        layout->addWidget(phoneModifyEdit, 3, 2);
        layout->addWidget(phoneSubmitBtn, 3, 3);
    });




#if TEST_UI
    avatarBtn->setIcon(QIcon(":/resource/images/avatar.jpg"));
    idLabel->setText("1234");
    nameLabel->setText("张三");
    descLabel->setText("每天认真敲代码！！！");
    phoneLabel->setText("15734562367");
#endif

}

